# -*- coding: utf-8 -*-
# Time: 2018/10/13 19:01:30
# File Name: ex_interval.py
import datetime
import os
from apscheduler.schedulers.blocking import BlockingScheduler

from api import models


def tick():
    print('Tick! The time is: %s' % datetime.now())


def tick1():
    print('Tick11111! The time is: %s' % datetime.now())


def test_schedule():
    scheduler = BlockingScheduler()
    scheduler.add_job(tick, 'interval', seconds=3)
    print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C    '))

    try:
        scheduler.start()
    except (KeyboardInterrupt, SystemExit):
        pass


if __name__ == '__main__':
    now_time = datetime.datetime.now()
    day_num = now_time.isoweekday()
    week_day = (now_time - datetime.timedelta(days=day_num))
    # 一周前的
    try:
        models.Sample.objects.exclude(prod_time__range=(week_day, now_time)).delete()
    except Exception as e:
        print(e)

